<template>
  <div class="app-container p-rel">
    <div class="container-title">查询</div>
    <form-edit class="p-abs" :detailForm="detailForm" :isEdit="isEdit" @submitForm="submitForm" :editVisible.sync="editVisible" v-if="editVisible"></form-edit>
    <el-form :model="queryParams" class=""  ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="85px">
      <el-row :gutter="15">
        <el-col :lg="8" :xl="6">
          <el-form-item label="设备编码" prop="code">
            <el-input
              v-model="queryParams.code"
              placeholder="请输入设备编码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
<!--        <el-col :lg="8" :xl="6">
          <el-form-item label="监测值" prop="monitorValue">
            <el-input
              v-model="queryParams.monitorValue"
              placeholder="请输入监测值"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>-->
        <el-col :lg="8" :xl="6">
          <el-button type="primary" icon="" size="" @click="handleQuery">搜索</el-button>
          <el-button icon="" size="" @click="resetQuery">重置</el-button>
        </el-col>
      </el-row>
    </el-form>

<!--    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          plain
          size="mini"
          @click="handleAdd"
          v-hasPermi="['environment:noiseData:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['environment:noiseData:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['environment:noiseData:remove']"
        >删除</el-button>
      </el-col>-->
      <!--<el-col :span="1.5">
       <el-button
          plain
          size="mini"
          @click="handleExport"
          v-hasPermi="['environment:noiseData:export']"
        >导出</el-button>
      </el-col>-->
      <!--<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->

    <el-table v-loading="loading" :data="noiseDataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="id" align="center" prop="id" />-->
      <el-table-column label="监测时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="设备名称" align="center" prop="equipmentName" />
      <el-table-column label="设备编码" align="center" prop="code" />
      <el-table-column label="监测值" align="center" prop="monitorValue" />

<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row,2)"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row,1)"
            v-hasPermi="['environment:noiseData:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['environment:noiseData:remove']"
          >删除</el-button>
        </template>
      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listNoiseData, getNoiseData, delNoiseData, addNoiseData, updateNoiseData } from "@/api/environment/noiseData";
import formEdit from './editFrom.vue'
export default {
  name: "NoiseData",
  components:{ formEdit },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 噪音数据表格数据
      noiseDataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        monitorValue: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      detailForm:{},
      isEdit:false,
      editVisible:false,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询噪音数据列表 */
    getList() {
      this.loading = true;
      listNoiseData(this.queryParams).then(response => {
        this.noiseDataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        code: null,
        monitorValue: null,
        createId: null,
        createBy: null,
        createTime: null,
        updateId: null,
        updateBy: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.detailForm = {}
      this.isEdit = false
      this.editVisible = true
    },
    /** 修改按钮操作 */
    handleUpdate(row,type) {
      // this.reset();
      const id = row.id || this.ids
      getNoiseData(id).then(response => {
        this.detailForm = response.data
        if(type == 1){
          this.isEdit = true
        }else{ // 查看
          this.isEdit = false
        }
        this.editVisible = true

      });
    },
    /** 提交按钮 */
    submitForm(form,id) {
      if (id != null) {
        updateNoiseData(form).then(response => {
          this.$modal.msgSuccess("修改成功");
          this.editVisible = false;
          this.getList();
        });
      } else {
        addNoiseData(form).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.editVisible = false;
          this.getList();
        });
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      var ids ;
      if (row.id) {
        ids = row.id;
      } else {
        ids = this.ids
      }
      this.$modal.confirm('是否确认删除噪音数据编号为"' + ids + '"的数据项？').then(function() {
        return delNoiseData(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('environment/noiseData/export', {
        ...this.queryParams
      }, `noiseData_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
